LIBNAME=secureagent
SOURCES=secureagent.c utils.c
COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer -std=c99
COMMON_FLAGS+= -W -Wall -Wextra -pedantic -Werror -Wno-unused -Wno-parentheses
CFLAGS=-O2 $(COMMON_FLAGS) 
OBJECTS=$(SOURCES:%.c=%.o)
LIBRARY=lib$(LIBNAME).so
LDFLAGS=-Wl -static-libgcc -mimpure-text
LIBRARIES=-lc
LINK_SHARED=$(LINK.c) -shared -o $@

ifeq ($(OSNAME), linux)
	LIBRARY=lib$(LIBNAME).so
	COMMON_FLAGS=-fno-strict-aliasing -fPIC -fno-omit-frame-pointer
	COMMON_FLAGS+= -W -Wall  -Wno-unused -Wno-parentheses $(DEBUG_FLAGS)
	LDFLAGS=-Wl,-soname=$(LIBRARY) -static-libgcc -mimpure-text
endif

ifeq ($(shell uname),Darwin)
	LIBRARY=lib$(LIBNAME).dylib
endif

CFLAGS += -I.
CFLAGS += -I$(J2SDK)/include -I$(J2SDK)/include/$(OSNAME)

# Default rule
all: $(LIBRARY)

# Build native library
$(LIBRARY): $(OBJECTS)
	$(LINK_SHARED) $(OBJECTS) $(LIBRARIES)

# Cleanup the built bits
clean:
	rm -f $(LIBRARY) $(OBJECTS)

%.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<
